package View;

import Model.FlightServer;
import Model.StartServer;
import UCM.UCStartServer;
import UCM.UCStopServer;
import java.awt.*;
import java.awt.event.*;
import java.util.Observable;
import java.util.Observer;
import javax.swing.*;

/**
 * Creates the Server GUI
 * @author Jason Sorbello
 */
public class ServerGUI extends JFrame implements Observer {

   // private final UCStartServer UCStart = new UCStartServer(this);
    private StartServer model;

    final int TEXT_X = 20;
    final int TEXT_Y = 20;
    private JTextArea text = new JTextArea(TEXT_X, TEXT_Y);
    private JPanel textPanel = new JPanel();
    private JPanel buttons = new JPanel();
    private JButton startBtn = new JButton("Start");
    private JButton stopBtn = new JButton("Stop");
    JScrollPane textScroller = new JScrollPane(text);
    
    public void addText(String a) {
        text.append(a);
    }

    public void loadTo(StartServer model) {
        this.model = model;
    }

    public ServerGUI() {
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setTitle("Flight Server");
        buttons.add(startBtn);
        buttons.add(stopBtn);
        stopBtn.addActionListener(new AdapterUCCToAL(new UCStopServer()));
        startBtn.addActionListener(new AdapterUCCToAL(new UCStartServer()));

        text = new JTextArea(TEXT_X, TEXT_Y);
        text.setEditable(false);
        text.setLineWrap(true);
        textPanel.add(textScroller);

        this.add(textPanel, BorderLayout.SOUTH);
        this.add(buttons, BorderLayout.NORTH);

        this.pack();
        this.setVisible(true);
    }

    public void update(Observable o, Object arg) {
        text.append("Connected to server");
    }
}
